<?php echo $header; ?>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<div class="box">
<div class="left"></div>
<div class="right"></div>
<div class="heading">
    <h1 style="background-image: url('view/image/product.png');"><?php echo $heading_title; ?></h1>
    <div class="buttons"><a onclick="$('#form').submit();" class="button"><span><?php echo $button_save; ?></span></a><a onclick="location = '<?php echo $cancel; ?>';" class="button"><span><?php echo $button_cancel; ?></span></a></div>
</div>
<div class="content">
<div id="tabs" class="htabs">
    <a tab="#tab_general"><?php echo $tab_general; ?></a><a tab="#tab_data"><?php echo $tab_data; ?></a><a tab="#tab_links"><?php echo $tab_links; ?></a><a tab="#tab_option"><?php echo $tab_option; ?></a>
    <a tab="#tab_discount"><?php echo $tab_discount; ?></a>
    <a tab="#tab_special"><?php echo $tab_special; ?></a>
    <a tab="#tab_image"><?php echo $tab_image; ?></a>
    <?php if(isset($simple_color)){ ?>
    <a tab="#tab_color"><?php echo $tab_color; ?></a>
    <?php }elseif(1==0){ ?>
    <a tab="#tab_color"><?php echo $tab_color; ?></a>
    <?php } ?>
</div>
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<div id="tab_general">
<div id="languages" class="htabs">
    <?php foreach ($languages as $language) { ?>
    <a tab="#language<?php echo $language['language_id']; ?>"><img src="view/image/flags/<?php echo $language['image']; ?>" title="<?php echo $language['name']; ?>" /> <?php echo $language['name']; ?></a>
    <?php } ?>
</div> 
<?php foreach ($languages as $language) { ?>
<div id="language<?php echo $language['language_id']; ?>">
<table class="form">
<tr>
    <td><span class="required">*</span> <?php echo $entry_name; ?></td>
    <td><input type="text" name="product_description[<?php echo $language['language_id']; ?>][name]" size="100" value="<?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['name'] : ''; ?>" />
        <?php if (isset($error_name[$language['language_id']])) { ?>
        <span class="error"><?php echo $error_name[$language['language_id']]; ?></span>
        <?php } ?></td>
            </tr>
            <tr>
              <td><?php echo $entry_description; ?></td>
              <td><textarea name="product_description[<?php echo $language['language_id']; ?>][description]" id="description<?php echo $language['language_id']; ?>"><?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['description'] : ''; ?></textarea></td>
            </tr>
            <tr>               
              <td><?php echo $entry_meta_keywords; ?></td>
              <td><textarea name="product_description[<?php echo $language['language_id']; ?>][meta_keywords]" cols="40" rows="5"><?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['meta_keywords'] : ''; ?></textarea></td>
            </tr>
            <tr>
              <td><?php echo $entry_meta_description; ?></td>
              <td><textarea name="product_description[<?php echo $language['language_id']; ?>][meta_description]" cols="40" rows="5"><?php echo isset($product_description[$language['language_id']]) ? $product_description[$language['language_id']]['meta_description'] : ''; ?></textarea></td>
            </tr>              
			<tr>
              <td><?php echo $entry_tags; ?></td>
              <td><input type="text" name="product_tags[<?php echo $language['language_id']; ?>]" value="<?php echo isset($product_tags[$language['language_id']]) ? $product_tags[$language['language_id']] : ''; ?>" size="80"/></td>
            </tr>
          </table>
        </div>
		<?php } ?>
      </div>
      <div id="tab_data">
        <table class="form">
          <!--
          <tr>
            <td><span class="required">*</span> <?php echo $entry_model; ?></td>
            <td><input type="text" name="model" value="<?php echo $model; ?>" />
              <?php if ($error_model) { ?>
              <span class="error"><?php echo $error_model; ?></span>
              <?php } ?></td>
          </tr>
          -->
          <tr>
            <td><span class="required">*</span><?php echo $entry_sku; ?></td>
            <td>
            	<input type="text" name="sku" value="<?php echo $sku; ?>" />
                <input type="hidden" name="product_number" value="" />
            	<?php if ($error_sku) { ?>
              		<span class="error"><?php echo $error_sku; ?></span>
              	<?php } ?>
            </td>
          </tr>           
          <tr>
            <td><?php echo $entry_status; ?></td>
            <td><select name="status">
                <?php if ($status) { ?>
                <option value="1" selected="selected"><?php echo $text_enabled; ?></option>
                <option value="0"><?php echo $text_disabled; ?></option>
                <?php } else { ?>
                <option value="1"><?php echo $text_enabled; ?></option>
                <option value="0" selected="selected"><?php echo $text_disabled; ?></option>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_price; ?></td>
            <td><input type="text" name="price" value="<?php echo $price; ?>" /></td>
          </tr>
		  <tr>
            <td><?php echo $entry_cost; ?></td>
            <td><input type="text" name="cost" value="<?php echo $cost; ?>" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_tax_class; ?></td>
            <td><select name="tax_class_id">
                <option value="0"><?php echo $text_none; ?></option>
                <?php foreach ($tax_classes as $tax_class) { ?>
                <?php if ($tax_class['tax_class_id'] == $tax_class_id) { ?>
                <option value="<?php echo $tax_class['tax_class_id']; ?>" selected="selected"><?php echo $tax_class['title']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $tax_class['tax_class_id']; ?>"><?php echo $tax_class['title']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_quantity; ?></td>
            <td><input type="text" name="quantity" value="<?php echo $quantity; ?>" size="2" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_minimum; ?></td>
            <td><input type="text" name="minimum" value="<?php echo $minimum; ?>" size="2" /></td>
          </tr>
		  <tr>
		    <td><?php echo $entry_subtract; ?></td>
		    <td><select name="subtract">
			  <?php if ($subtract) { ?>
			  <option value="1" selected="selected"><?php echo $text_yes; ?></option>
			  <option value="0"><?php echo $text_no; ?></option>
			  <?php } else { ?>
			  <option value="1"><?php echo $text_yes; ?></option>
			  <option value="0" selected="selected"><?php echo $text_no; ?></option>
			  <?php } ?>
			</select></td>
		  </tr>
          <tr>
            <td><?php echo $entry_stock_status; ?></td>
            <td><select name="stock_status_id">
                <?php foreach ($stock_statuses as $stock_status) { ?>
                <?php if ($stock_status['stock_status_id'] == $stock_status_id) { ?>
                <option value="<?php echo $stock_status['stock_status_id']; ?>" selected="selected"><?php echo $stock_status['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $stock_status['stock_status_id']; ?>"><?php echo $stock_status['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_shipping; ?></td>
            <td><?php if ($shipping) { ?>
              <input type="radio" name="shipping" value="1" checked="checked" />
              <?php echo $text_yes; ?>
              <input type="radio" name="shipping" value="0" />
              <?php echo $text_no; ?>
              <?php } else { ?>
              <input type="radio" name="shipping" value="1" />
              <?php echo $text_yes; ?>
              <input type="radio" name="shipping" value="0" checked="checked" />
              <?php echo $text_no; ?>
              <?php } ?></td>
          </tr>
		  <tr>
            <td>
				Delivery time 3-6 days
				<span class="help">Default delivery time is 1-3 days</span>
			</td>
            <td>
				<?php if ($delay_delivery) { ?>
					<input type="radio" name="delay_delivery" value="1" checked="checked" /> <?php echo $text_yes; ?>
					<input type="radio" name="delay_delivery" value="0" /> <?php echo $text_no; ?>
				<?php } else { ?>
					<input type="radio" name="delay_delivery" value="1" /> <?php echo $text_yes; ?>
					<input type="radio" name="delay_delivery" value="0" checked="checked" /> <?php echo $text_no; ?>
				<?php } ?>
				<!-- input type="checkbox" name="delay_delivery" value="1" <?php echo $delay_delivery ? 'checked="checked" ' : '' ?>/ -->
			</td>
          </tr>
          <tr>
            <td><?php echo $entry_size_guide; ?></td>
            <td>
                <?php 
                $size_guides = array(
                    'women'             => 'SailXtreme Dame',
                    'men'               => 'SailXtreme Herre',             
                    'hh_women'          => 'Helly Hansen Sportswear Dame',
                    'hh_men'            => 'Helly Hansen Sportswear Herre',      
                    'hh_workwear'       => 'Helly Hansen Workwear',
                    'hh_hue'            => 'Helly Hansen Hue',
                    'hh_sock'           => 'Helly Hansen Sokker', 
                    'hh_glove'          => 'Helly Hansen Handsker',                     
                    'ocean_class'       => 'Ocean Working Class',					
					'ocean_rainwear'	=> 'Ocean Måleskema Børn', 
                    'hempel_farvekort'  => 'Hempel Farvekort',
                    'kansas_maleskema'  => 'Kansas måleskema',                    
                    'h2o_sportswear_maleskema_women'    => 'H2O Sportswear Måleskema Dame',
                    'h2o_sportswear_maleskema_men'      => 'H2O Sportswear Måleskema Herre', 
                    'peak_performance_women'            => 'Peak Performance Dame',
                    'peak_performance_men'              => 'Peak Performance Herre',    
                    'redgreen_women'    => 'Redgreen Dame',
                    'redgreen_men'      => 'Redgreen Herre',
                    'hunter_women'      => 'Hunter måleskema',
                    'fjallraven_women'  => 'Fjällräven Måleskemaer Dame',
                    'fjallraven_men'    => 'Fjällräven Måleskemaer Herre',
                    'hestra_handske'    => 'Hestra handskestørrelser',
                    'ox_on'             => 'OX-ON Måleskema',
                    'sebago_women'      => 'Sebago Måleskema Dame',
                    'sebago_men'        => 'Sebago Måleskema Herre',
                    'signal_women'      => 'Signal Måleskema Dame', 
                    'signal_men'        => 'Signal Måleskema Herre',
                    'acode'             => 'Acode Måleskema',
                    'pelle_p_men'       => 'Pelle P Måleskema Herre',
                    'pelle_p_women'     => 'Pelle P Måleskema Dame',
                                                            
                    //'b_small'       => 'Beklædningsmål',
                    //'euro_size'     => 'Europe vanlig',
                    //'euro_high'     => 'Europe høj',
                    //'euro_d'        => 'Europe D-størrelser',
                    //'glove_size'    => 'Hanske str.',
                    //'jean_size'     => 'Jeansstørrelser',                     
                );                
                ?>
                <select name="size_guide">
                    <option value="none"><?php echo $text_none; ?></option>
                    <?php foreach ($size_guides as $key => $val) { ?>
                        <option value="<?php echo $key; ?>" <?php echo ($size_guide == $key) ? 'selected="selected"' : ''; ?>><?php echo $val; ?></option>
                    <?php } ?>
                </select>
            </td>
          </tr>        
          <tr>
            <td><?php echo $entry_location; ?></td>
            <td><input type="text" name="location" value="<?php echo $location; ?>" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_keyword; ?></td>
            <td><input type="text" name="keyword" value="<?php echo $keyword; ?>" size= "100" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_image; ?></td>
            <td><input type="hidden" name="image" value="<?php echo $image; ?>" id="image" />
              <img src="<?php echo $preview; ?>" alt="" id="preview" class="image" onclick="image_upload('image', 'preview');" /></td>
          </tr>		  
          <tr style="display:none; visibility:hidden;">		  
            <td><?php echo $entry_video; ?></td>
            <td>
                <input type="text" name="video" value="<?php echo $video; ?>" id="video" />
                <a id="video_preview" href="#" class="video" style="margin-left:10px;" /><?php echo $entry_video_upload; ?></a>
            </td>            
          </tr>
		  <tr>
            <td>Youtube video</td>
            <td>
                ID:&nbsp;&nbsp;<input type="text" name="youtube_video" value="<?php echo $youtube_video; ?>" size="20" />&nbsp;&nbsp;&nbsp;&nbsp;
               <p style="display:none; visibility:hidden;"> 
					Width:&nbsp;&nbsp;<input type="text" name="youtube_video_width" value="<?php echo $youtube_video_width; ?>" size="5" />&nbsp;&nbsp;&nbsp;&nbsp;
					Height:&nbsp;&nbsp;<input type="text" name="youtube_video_height" value="<?php echo $youtube_video_height; ?>" size="5" />
				</p>
            </td>            
          </tr>
          <tr>
            <td><?php echo $entry_date_available; ?></td>
            <td><input type="text" name="date_available" value="<?php echo $date_available; ?>" size="12" class="date" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_sort_order; ?></td>
            <td><input type="text" name="sort_order" value="<?php echo $sort_order; ?>" size="2" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_dimension; ?></td>
            <td><input type="text" name="length" value="<?php echo $length; ?>" size="4" />
              <input type="text" name="width" value="<?php echo $width; ?>" size="4" />
              <input type="text" name="height" value="<?php echo $height; ?>" size="4" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_length; ?></td>
            <td><select name="length_class_id">
                <?php foreach ($length_classes as $length_class) { ?>
                <?php if ($length_class['length_class_id'] == $length_class_id) { ?>
                <option value="<?php echo $length_class['length_class_id']; ?>" selected="selected"><?php echo $length_class['title']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $length_class['length_class_id']; ?>"><?php echo $length_class['title']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>
          <tr>
            <td><?php echo $entry_weight; ?></td>
            <td><input type="text" name="weight" value="<?php echo $weight; ?>" /></td>
          </tr>
          <tr>
            <td><?php echo $entry_weight_class; ?></td>
            <td><select name="weight_class_id">
                <?php foreach ($weight_classes as $weight_class) { ?>
                <?php if ($weight_class['weight_class_id'] == $weight_class_id) { ?>
                <option value="<?php echo $weight_class['weight_class_id']; ?>" selected="selected"><?php echo $weight_class['title']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $weight_class['weight_class_id']; ?>"><?php echo $weight_class['title']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>  
          <tr>
            <td><?php echo $entry_low_stock_warning; ?></td>
            <td>
                <input type="text" name="low_stock_warning" value="<?php echo $low_stock_warning; ?>" />                
            </td>
          </tr> 
          <tr>
            <td><?php echo $entry_delivery_time_instock; ?></td>
            <td>
                <input type="text" name="delivery_time_instock" value="<?php echo $delivery_time_instock; ?>" />                
            </td>
          </tr> 
          <tr>
            <td><?php echo $entry_delivery_time_outstock; ?></td>
            <td>
                <input type="text" name="delivery_time_outstock" value="<?php echo $delivery_time_outstock; ?>" />                
            </td>
          </tr> 
        </table>
      </div>
      <div id="tab_links">
        <table class="form">
          <tr>
            <td><?php echo $entry_manufacturer; ?></td>
            <td><select name="manufacturer_id">
                <option value="0" selected="selected"><?php echo $text_none; ?></option>
                <?php foreach ($manufacturers as $manufacturer) { ?>
                <?php if ($manufacturer['manufacturer_id'] == $manufacturer_id) { ?>
                <option value="<?php echo $manufacturer['manufacturer_id']; ?>" selected="selected"><?php echo $manufacturer['name']; ?></option>
                <?php } else { ?>
                <option value="<?php echo $manufacturer['manufacturer_id']; ?>"><?php echo $manufacturer['name']; ?></option>
                <?php } ?>
                <?php } ?>
              </select></td>
          </tr>         
          <tr>
            <td><?php echo $entry_category; ?></td>
            <td id="category_list">
                <div class="scrollbox">
                <?php $class = 'odd'; ?>
                <?php foreach ($categories as $category) { ?>
                <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                <div class="<?php echo $class; ?>">
                  <?php if (in_array($category['category_id'], $product_category)) { ?>
                  <input type="checkbox" name="product_category[]" value="<?php echo $category['category_id']; ?>" checked="checked" />
                  <?php echo $category['name']; ?>
                  <?php } else { ?>
                  <input type="checkbox" name="product_category[]" value="<?php echo $category['category_id']; ?>" />
                  <?php echo $category['name']; ?>
                  <?php } ?>
                </div>
                <?php } ?>
              </div></td>
          </tr>
          <tr style="display: none;">
            <td><?php echo $entry_store; ?></td>
            <td><div class="scrollbox1">
                <?php $class = 'even'; ?>
                <div class="<?php echo $class; ?>">
                  <?php if (in_array(0, $product_store)) { ?>
                  <input type="checkbox" name="product_store[]" value="0" checked="checked" />
                  <?php echo $text_default; ?>
                  <?php } else { ?>
                  <input type="checkbox" name="product_store[]" value="0" />
                  <?php echo $text_default; ?>
                  <?php } ?>
                </div>
                <?php foreach ($stores as $store) { ?>
                <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                <div class="<?php echo $class; ?>">
                  <?php if (in_array($store['store_id'], $product_store)) { ?>
                  <input type="checkbox" name="product_store[]" value="<?php echo $store['store_id']; ?>" checked="checked" />
                  <?php echo $store['name']; ?>
                  <?php } else { ?>
                  <input type="checkbox" name="product_store[]" value="<?php echo $store['store_id']; ?>" />
                  <?php echo $store['name']; ?>
                  <?php } ?>
                </div>
                <?php } ?>
              </div></td>
          </tr>
          <!--
          <tr>
            <td><?php echo $entry_download; ?></td>
            <td><div class="scrollbox">
                <?php $class = 'odd'; ?>
                <?php foreach ($downloads as $download) { ?>
                <?php $class = ($class == 'even' ? 'odd' : 'even'); ?>
                <div class="<?php echo $class; ?>">
                  <?php if (in_array($download['download_id'], $product_download)) { ?>
                  <input type="checkbox" name="product_download[]" value="<?php echo $download['download_id']; ?>" checked="checked" />
                  <?php echo $download['name']; ?>
                  <?php } else { ?>
                  <input type="checkbox" name="product_download[]" value="<?php echo $download['download_id']; ?>" />
                  <?php echo $download['name']; ?>
                  <?php } ?>
                </div>
                <?php } ?>
              </div></td>
          </tr>
          -->  
                     
          <tr>
            <td><?php echo $entry_related; ?></td>
            <td>
                <table>
                    <tr>
                      <td style="padding: 0;" colspan="3"><select id="category" style="margin-bottom: 5px;" onchange="getProducts();">
                          <?php foreach ($categories as $category) { ?>
                          <option value="<?php echo $category['category_id']; ?>"><?php echo $category['name']; ?></option>
                          <?php } ?>
                        </select></td>
                    </tr>
                    <tr>
                      <td style="padding: 0;"><select multiple="multiple" id="product" size="10" style="width: 350px;">
                        </select></td>
                      <td style="vertical-align: middle;"><input type="button" value="--&gt;" onclick="addRelated();" />
                        <br />
                        <input type="button" value="&lt;--" onclick="removeRelated();" /></td>
                      <td style="padding: 0;"><select multiple="multiple" id="related" size="10" style="width: 350px;">
                        </select></td>
                    </tr>
                  </table>
                  <div id="product_related">
                    <?php foreach ($product_related as $related_id) { ?>
                    <input type="hidden" name="product_related[]" value="<?php echo $related_id; ?>" />                    
                    <?php } ?>
                  </div>
                  <div>                                         
                    <?php if($product_cross_related){ ?> 
                        <input type="checkbox" name="product_cross_related" checked="checked" value="1" />&nbsp;Cross-reference                        
                    <?php }else{ ?>
                        <input type="checkbox" name="product_cross_related" value="1" />&nbsp;Cross-reference                        
                    <?php } ?>                    
                  </div> 
              </td>
          </tr>                     
        </table>
      </div>
      <div id="tab_option">
        <div style="padding-bottom: 30px; margin:0 0 15px 15px; border-bottom: solid 1px #000;">  
            <b>Select attribute group:</b> <br />             
            <select id="attribute_group" name="option_attribute_id" style="width: 150px; margin-right:20px;">   
                <?php foreach($attribute_group as $attribute_item){ ?>                      
                    <option value="<?php echo $attribute_item['attribute_id']; ?>" rel="<?php echo $attribute_item['sort_order']; ?>" alt="<?php echo $attribute_item['name']; ?>">&nbsp;<?php echo $attribute_item['description']; ?></option>                                            
                <?php } ?>
            </select>  
            <a onclick="addAttribute();" class="button"><span><?php echo $button_add_attribute; ?></span></a>  
            <?php if(isset($show_attribute_option)){ ?>
            <a onclick="updateAttribute();" class="button"><span><?php echo $button_update_attribute; ?></span></a>  
            <?php } ?>
        </div>
        <div style="width: 95%; display: inline-block; padding-bottom: 30px; margin-left:15px;">
            <b><?php echo 'Product attributes'; ?></b><br />
            <?php if(isset($show_attribute_option)){ ?>
            <div style="width: 200px; height: 300px; float: left;">            
                <select id="option" size="21" style="width: 100%;" multiple="multiple">                                          
                    <?php $option_value_row = 0; ?>
                    <?php foreach ($product_options as $product_option) { ?>
                        <?php $option_row = $product_option['attribute_id']; ?>         
                        <option value="option<?php echo $option_row; ?>"><?php echo $product_option['description']; //$product_option['language'][$language_id]['name']; ?></option>
                        <?php if ($product_option['product_option_value']) { ?>
                            <?php foreach ($product_option['product_option_value'] as $product_option_value) { ?>
                                <?php foreach ($languages as $language) { ?>
                                    <?php if ($language['language_id'] == $language_id) { ?>
                                        <option value="option<?php echo $option_row; ?>_<?php echo $option_value_row; ?>" rel="option<?php echo $option_row; ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $product_option_value['language'][$language['language_id']]['name']; ?></option>
                                        <?php $option_value_row++; ?>
                                    <?php } ?>
                                <?php } ?>
                            <?php } ?>
                        <?php } ?>                       
                    <?php } ?>
                </select>
            </div> 
            <div style="width: 200px; height: 300px; float: left;">            
                <select id="option" name="product_option_selected" size="21" style="width: 100%;" multiple="multiple">                                          
                    <?php $option_value_row = 0; ?>
                    <?php foreach ($attribute_groups as $product_option) { ?>
                        <?php $option_row = $product_option['attribute_id']; ?>         
                        <option value="option<?php echo $option_row; ?>"><?php echo $product_option['description']; //$product_option['language'][$language_id]['name']; ?></option>
                        <?php if ($product_option['values']) { ?>
                            <?php foreach ($product_option['values'] as $product_option_value) { ?>
                                <option value="option<?php echo $option_row; ?>_<?php echo $option_value_row; ?>" rel="option<?php echo $option_row; ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $product_option_value['name']; ?></option>
                                <?php $option_value_row++; ?>
                            <?php } ?>
                        <?php } ?>                       
                    <?php } ?>
                </select>
            </div>  
            <?php } ?>
            
            <div style="float: left;">
                <div style="width: 200px; height: 310px;" class="scrollbox">  
                    <div id="option">                 
                        <?php $option_value_row = 0; ?>                                         
                        <?php foreach ($attribute_groups as $product_option) { ?>                      
                            <?php $option_row = $product_option['attribute_id']; ?>                        
                                <div class="attribute_item attribute_header" rel="option<?php echo $option_row; ?>">
                                    <?php echo $product_option['description']; ?>                      
                                </div>
                                <?php if ($product_option['values']) { ?>                                       
                                    <?php foreach ($product_option['values'] as $product_option_value) { ?> 
                                        <?php $checked = $product_option_value['selected'] ? 'checked="checked"' : ''; ?>
                                        <div class="attribute_item" rel="option<?php echo $option_row; ?>_<?php echo $option_value_row; ?>" alt="option<?php echo $option_row; ?>">                                             
                                            &nbsp;&nbsp;&nbsp;&nbsp;<input class="attribute_item_value" type=checkbox name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][select_attribute]" alt="option<?php echo $option_row; ?>_<?php echo $option_value_row; ?>" rel="option<?php echo $option_row; ?>" <?php echo $checked; ?> />
                                            &nbsp;&nbsp;<?php echo $product_option_value['name']; ?>
                                        </div> 
                                        <?php $option_value_row++; ?>                                        
                                    <?php } ?>
                                <?php } ?>   
                        <?php } ?> 
                    </div>               
                </div>
            </div>
                      
            <div id="options" style="margin-left: 215px;">              
            <?php $option_row = 0; ?>
            <?php $option_value_row = 0; ?>
            <?php //foreach ($product_options as $product_option) { ?>
            <?php foreach ($attribute_groups as $product_option) { ?>
                <?php $option_row = $product_option['attribute_id']; ?> 
                <div id="option<?php echo $option_row; ?>" class="option">                     
                    <table class="form">
                        <tr>
                            <td width="30%">
                                <?php foreach ($languages as $language) { ?>
                                    <input type="hidden" name="product_option[<?php echo $option_row; ?>][language][<?php echo $language['language_id']; ?>][name]" value="<?php echo $product_option['language'][$language['language_id']]['name']; ?>" />                        
                                <?php } ?> 
                                <input type="hidden" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][description]" value="<?php echo $product_option['description']; ?>" />
                                <input type="hidden" name="product_option[<?php echo $option_row; ?>][sort_order]" value="<?php echo $product_option['sort_order']; ?>" />
                                <input type="hidden" name="product_option[<?php echo $option_row; ?>][attribute_id]" value="<?php echo $product_option['attribute_id']; ?>" />
                                <input type="hidden" name="product_option[<?php echo $option_row; ?>][option_id]" value="<?php echo $product_option['product_option_id']; ?>" />
                        
                                <b>Attribute name:</b>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $product_option['language'][$language_id]['name'] . '&nbsp;&nbsp;(' . $product_option['description'] . ')'; ?>
                            </td>
                            <td width="50%"><b><?php echo $entry_sort_order; ?></b>&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $product_option['sort_order']; ?></td>
                            <td width="20%" align="right"><a onclick="removeOption('<?php echo $option_row; ?>');" class="button"><span><?php echo $button_remove_attribute; ?></span></a></td>
                        </tr>
                    </table>
                    <div id="option_values<?php echo $option_row; ?>"> 
                        <?php //if ($product_option['product_option_value']) { ?>
                        <?php if ($product_option['values']) { ?>
                            <?php //foreach ($product_option['product_option_value'] as $product_option_value) { ?>
                            <?php foreach ($product_option['values'] as $product_option_value) { ?>
                                <div id="option<?php echo $option_row; ?>_<?php echo $option_value_row; ?>" class="option_value">                                                                    
                                    <table class="form">
                                        <tr>
                                            <td>                                                
                                                <?php foreach ($languages as $language) { ?>                                                    
                                                    <input type="hidden" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][language][<?php echo $language['language_id']; ?>][name]" value="<?php echo $product_option_value['name']; //$product_option_value['language'][$language['language_id']]['name']; ?>" />                                                    
                                                <?php } ?>                                                
                                                <input type="hidden" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][sort_order]" value="<?php echo $product_option_value['sort_order']; ?>" />                                                                                                                                     
                                                <input type="hidden" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][attribute_id]" value="<?php echo $product_option_value['attribute_id']; ?>" />
                                                <input type="hidden" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][attribute_value_id]" value="<?php echo $product_option_value['attribute_value_id']; ?>" class="attribute_value_id<?php echo $option_row; ?>" />                                                
                                                <input type="hidden" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][option_value_id]" value="<?php echo $product_option_value['product_option_value_id']; ?>" />
                                                <?php echo 'Attribute value:' . '&nbsp;&nbsp;' . $product_option_value['name']; //$product_option_value['language'][$language_id]['name']; ?>
                                            </td>
                                            <td><?php echo $entry_sort_order . '&nbsp;&nbsp;' . $product_option_value['sort_order']; ?></td>                                            
                                        </tr>
                                        <tr>
                                            <td><?php echo $entry_product_option_number; ?></td>
                                            <td><input type="text" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][product_option_number]" value="<?php echo $product_option_value['product_option_number']; ?>" /></td> 
                                        </tr>   
                                        <tr>
                                            <td><?php echo $entry_quantity; ?></td>
                                            <td><input type="text" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][quantity]" value="<?php echo $product_option_value['quantity']; ?>" size="2" /></td> 
                                        </tr>   
                                        <tr>
                                            <td><?php echo $entry_subtract; ?></td>
                                            <td>
                                                <select name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][subtract]">
                                                    <?php if ($product_option_value['subtract']) { ?>
                                                        <option value="1" selected="selected"><?php echo $text_yes; ?></option>
                                                        <option value="0"><?php echo $text_no; ?></option>
                                                    <?php } else { ?>
                                                        <option value="1"><?php echo $text_yes; ?></option>
                                                        <option value="0" selected="selected"><?php echo $text_no; ?></option>
                                                    <?php } ?>
                                                </select>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td><?php echo $entry_price; ?></td>
                                            <td><input type="text" name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][price]" value="<?php echo $product_option_value['price']; ?>" /></td>
                                        </tr>
                                        <tr>
                                            <td><?php echo $entry_prefix; ?></td>
                                            <td>
                                                <select name="product_option[<?php echo $option_row; ?>][product_option_value][<?php echo $option_value_row; ?>][prefix]">
                                                    <?php  if ($product_option_value['prefix'] != '-') { ?>
                                                        <option value="+" selected="selected"><?php echo $text_plus; ?></option>
                                                        <option value="-"><?php echo $text_minus; ?></option>
                                                    <?php } else { ?>
                                                        <option value="+"><?php echo $text_plus; ?></option>
                                                        <option value="-" selected="selected"><?php echo $text_minus; ?></option>
                                                    <?php } ?>
                                                </select>
                                            </td>
                                        </tr>  
                                        <?php if(isset($show_attribute_option)){ ?>
                                        <tr>
                                            <td colspan="2"><a onclick="removeOptionValue('<?php echo $option_row; ?>_<?php echo $option_value_row; ?>');" class="button"><span><?php echo $button_remove_attribute_value; ?></span></a></td>                                  
                                        </tr>
                                        <?php } ?>
                                  </table>
                                </div>
                            <?php $option_value_row++; ?>
                        <?php } ?>
                    </div>
                </div>                  
                <?php } ?>
                <?php //$option_row++; ?>
            <?php } ?>
        </div>
        </div>
      </div>
      
      <!-- discount -->
      <div id="tab_discount">
        <table id="discount" class="list">
          <thead>
            <tr>
              <!-- td class="left"><?php echo $entry_customer_group; ?></td -->
              <!-- td class="left"><?php echo $entry_quantity; ?></td -->
              <!-- td class="left"><?php echo $entry_priority; ?></td -->
              <td class="left"><?php echo $entry_price; ?></td>
              <td class="left"><?php echo $entry_date_start; ?></td>
              <td class="left"><?php echo $entry_date_end; ?></td>
              <td></td>
            </tr>
          </thead>
          <?php $discount_row = 0; ?>
          <?php foreach ($product_discounts as $product_discount) { ?>
          <tbody id="discount_row<?php echo $discount_row; ?>">
            <tr>
              <!-- td class="left"><select name="product_discount[<?php echo $discount_row; ?>][customer_group_id]">
                  <?php foreach ($customer_groups as $customer_group) { ?>
                  <?php if ($customer_group['customer_group_id'] == $product_discount['customer_group_id']) { ?>
                  <option value="<?php echo $customer_group['customer_group_id']; ?>" selected="selected"><?php echo $customer_group['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select>
              </td -->
              <!-- td class="left"><input type="text" name="product_discount[<?php echo $discount_row; ?>][quantity]" value="<?php echo $product_discount['quantity']; ?>" size="2" /></td -->
              <!-- td class="left"><input type="text" name="product_discount[<?php echo $discount_row; ?>][priority]" value="<?php echo $product_discount['priority']; ?>" size="2" /></td -->
              <td class="left">
                <input type="text" name="product_discount[<?php echo $discount_row; ?>][price]" value="<?php echo $product_discount['price']; ?>" />
                <input type="hidden" name="product_discount[<?php echo $discount_row; ?>][customer_group_id]" value="<?php echo $product_discount['customer_group_id']; ?>" />
                <input type="hidden" name="product_discount[<?php echo $discount_row; ?>][priority]" value="<?php echo $product_discount['priority']; ?>" />
                <input type="hidden" name="product_discount[<?php echo $discount_row; ?>][quantity]" value="<?php echo $product_discount['quantity']; ?>" />                
              </td>
              <td class="left"><input type="text" name="product_discount[<?php echo $discount_row; ?>][date_start]" value="<?php echo $product_discount['date_start']; ?>" class="date" /></td>
              <td class="left"><input type="text" name="product_discount[<?php echo $discount_row; ?>][date_end]" value="<?php echo $product_discount['date_end']; ?>" class="date" /></td>
              <td class="left"><a onclick="removeDiscount(<?php echo $discount_row; ?>);" class="button"><span><?php echo $button_remove; ?></span></a></td>
            </tr>
          </tbody>
          <?php $discount_row++; ?>
          <?php } ?>
          <tfoot <?php echo ($discount_row > 0) ? 'style="display:none;"' : ''; ?>>
            <tr>
              <!-- td colspan="6"></td -->
              <td colspan="3"></td>
              <td class="left"><a onclick="addDiscount();" class="button"><span><?php echo $button_add_discount; ?></span></a></td>
            </tr>
          </tfoot>
        </table>
      </div>      
      <!-- discount --> 
      
      <div id="tab_special">
        <table id="special" class="list">
          <thead>
            <tr>
              <?php if(1==0){ ?>
              <td class="left"><?php echo $entry_customer_group; ?></td>
              <td class="left"><?php echo $entry_priority; ?></td>
              <?php } ?>
              <td class="left"><?php echo $entry_quantity; ?></td>
              <td class="left"><?php echo $entry_price; ?></td>
              <td class="left"><?php echo $entry_date_start; ?></td>
              <td class="left"><?php echo $entry_date_end; ?></td>
              <td></td>
            </tr>
          </thead>
          <?php $special_row = 0; ?>
          <?php foreach ($product_specials as $product_special) { ?>
          <tbody id="special_row<?php echo $special_row; ?>">
            <tr>
              <?php if(1==0){ ?><!--
              <td class="left">
                <select name="product_special[<?php echo $special_row; ?>][customer_group_id]">
                  <?php foreach ($customer_groups as $customer_group) { ?>
                  <?php if ($customer_group['customer_group_id'] == $product_special['customer_group_id']) { ?>
                  <option value="<?php echo $customer_group['customer_group_id']; ?>" selected="selected"><?php echo $customer_group['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select>
              </td>
              <td class="left"><input type="text" name="product_special[<?php echo $special_row; ?>][priority]" value="<?php echo $product_special['priority']; ?>" size="2" /></td>
              -->
              <?php } ?>
              <td class="left">
                <input type="hidden" name="product_special[<?php echo $special_row; ?>][customer_group_id]" value="<?php echo $product_special['customer_group_id']; ?>" />
                <input type="hidden" name="product_special[<?php echo $special_row; ?>][priority]" value="<?php echo $product_special['priority']; ?>" />
                <input type="text" name="product_special[<?php echo $special_row; ?>][quantity]" value="<?php echo $product_special['quantity']; ?>" size="5" />
              </td>
              <td class="left"><input type="text" name="product_special[<?php echo $special_row; ?>][price]" value="<?php echo $product_special['price']; ?>" /></td>
              <td class="left"><input type="text" name="product_special[<?php echo $special_row; ?>][date_start]" value="<?php echo $product_special['date_start']; ?>" class="date" /></td>
              <td class="left"><input type="text" name="product_special[<?php echo $special_row; ?>][date_end]" value="<?php echo $product_special['date_end']; ?>" class="date" /></td>
              <td class="left"><a onclick="$('#special_row<?php echo $special_row; ?>').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>
            </tr>
          </tbody>
          <?php $special_row++; ?>
          <?php } ?>
          <tfoot>
            <tr>
              <td colspan="4"></td>
              <td class="left"><a onclick="addSpecial();" class="button"><span><?php echo $button_add_special; ?></span></a></td>
            </tr>
          </tfoot>
        </table>
      </div>
      
      <div id="tab_image">
        <table id="images" class="list">
          <thead>
            <tr>
              <td class="left"><?php echo $entry_image; ?></td>
              <td></td>
            </tr>
          </thead>
          <?php $image_row = 0; ?>
          <?php foreach ($product_images as $product_image) { ?>
          <tbody id="image_row<?php echo $image_row; ?>">
            <tr>
              <td class="left"><input type="hidden" name="product_image[<?php echo $image_row; ?>]" value="<?php echo $product_image['file']; ?>" id="image<?php echo $image_row; ?>"  />
                <img src="<?php echo $product_image['preview']; ?>" alt="" id="preview<?php echo $image_row; ?>" class="image" onclick="image_upload('image<?php echo $image_row; ?>', 'preview<?php echo $image_row; ?>');" /></td>
              <td class="left"><a onclick="$('#image_row<?php echo $image_row; ?>').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>
            </tr>
          </tbody>
          <?php $image_row++; ?>
          <?php } ?>
          <tfoot>
            <tr>
              <td></td>
              <td class="left"><a onclick="addImage();" class="button"><span><?php echo $button_add_image; ?></span></a></td>
            </tr>
          </tfoot>
        </table>
        </div> 
	
        <!-- Color tab -->
	  	<?php $colors_row = 0; ?> 
        <?php $color_row = 0; ?>
        <?php $color_image_row = 0; ?>  
        <?php if(1==0) { ?>
	    <div id="tab_color">
            <div style="padding-bottom: 30px; margin:0 0 15px 15px; border-bottom: solid 1px #000;">  
                <b>Select color group:</b> <br />             
                <select id="color_group" name="color_attribute_id" style="width: 150px; margin-right:20px;">   
                    <?php foreach($color_group as $color_item){ ?>  
                        <?php $selected = ($color_item['attribute_id'] == $color_attribute_id) ? 'selected="selected"' : ''; ?>                                
                        <option value="<?php echo $color_item['attribute_id']; ?>" <?php echo $selected; ?>>&nbsp;<?php echo $color_item['name']; ?></option>                                            
                    <?php } ?>
                </select>  
                <a onclick="addColorValues();" class="button"><span><?php echo $button_add_color; ?></span></a>  
                <a onclick="updateColorValues();" class="button"><span><?php echo $button_update_color; ?></span></a>  
            </div>
	        <div style="display: inline-block; padding-bottom: 5px; margin-left:15px; width:95%;">		  
                <div style="width: 200px; height: 300px; float: left;">
                    <b><?php echo 'Product colors'; ?></b>		  			    
                    <select id="color_list" size="20" style="width: 100%;">
                        <?php $color_row = 0; ?>			  
                        <?php foreach ($product_colors as $color) { ?>			  
	                        <option value="option_color<?php echo $color_row; ?>">&nbsp;<?php echo $color['name']; ?></option>
	                        <?php $color_row++; ?>
                        <?php } ?>
                    </select>
                </div>
	            <div id="color_item" style="margin-left: 215px;">			 	          	
	                <?php $color_row = 0; ?>
				    <?php $color_image_row = 0; ?>
	                <?php foreach ($product_colors as $color) { ?>	
		                <div id="option_color<?php echo $color_row; ?>" class="option_color">
		                    <table class="form">
		              	        <tbody>
			                        <tr>			                            
                                        <td style="width:250px;">
                                            <input type="hidden" name="product_color[<?php echo $color_row; ?>][color_av_id]" value="<?php echo $color['attribute_value_id']; ?>" id="color_av_id<?php echo $color_row; ?>" />
                                            <input type="hidden" name="product_color[<?php echo $color_row; ?>][name]" value="<?php echo $color['name']; ?>" id="color_name<?php echo $color_row; ?>" />
                                            <input type="hidden" name="product_color[<?php echo $color_row; ?>][sort_order]" value="<?php echo $color['sort_order']; ?>" id="color_sort_order<?php echo $color_row; ?>" />
                                            <input type="hidden" name="product_color[<?php echo $color_row; ?>][color_image]" value="<?php echo $color['color_image']; ?>" id="color_image<?php echo $color_row; ?>" />
                                            <input type="hidden" name="product_color[<?php echo $color_row; ?>][color_id]" value="<?php echo $color['color_id']; ?>" id="color_id<?php echo $color_row; ?>" />
                                            <input type="hidden" name="product_color[<?php echo $color_row; ?>][option_id]" value="<?php echo $color['option_id']; ?>" id="color_option_id<?php echo $color_row; ?>" />
                                            <input type="hidden" name="product_color[<?php echo $color_row; ?>][color_ov_id]" value="<?php echo $color['option_value_id']; ?>" id="color_ov_id<?php echo $color_row; ?>" />
                                        
                                            <span style="float:left; margin-left:10px; width:50px;"><?php echo $color['name']; ?></span>
                                            <img src="<?php echo $color['color_preview']; ?>" alt="" id="color_image_preview<?php echo $color_row; ?>" class="image" style="float:left; margin-left:10px;" />
                                        </td>                                        
			                            <td><?php echo $entry_sort_order; ?>&nbsp;<?php echo $color['sort_order']; ?></td>
                                        <td><a onclick="removeColorOption('<?php echo $color_row; ?>');" class="button" style="float:right; margin-right:2px;"><span><?php echo 'Remove color'; ?></span></a></td>
			                        </tr>			                    
							        <tr>
							            <td colspan="3">
							  	            <table id="color_images<?php echo $color_row; ?>" class="list">
						                        <thead>
						                            <tr>
						                                <td class="left" style="width:70%;"><?php echo 'Image: ' . ($color['image_list'] ? '(Click on the image to change it)' : ''); //$entry_image; ?></td>
						                                <td></td>
						                            </tr>
						                        </thead>						          
						                        <?php foreach ($color['image_list'] as $image) { ?>
							                        <tbody id="color_image_row<?php echo $color_row . '_' . $color_image_row; ?>">
							                            <tr>
							                                <td class="left">
							              	                    <input type="hidden" name="product_color[<?php echo $color_row; ?>][image_list][<?php echo $color_image_row; ?>]" value="<?php echo $image['file']; ?>" id="color<?php echo $color_row . '_' . $color_image_row; ?>"  />
		                					                    <img src="<?php echo $image['preview']; ?>" alt="" id="color_preview<?php echo $color_row . '_' . $color_image_row; ?>" class="image" onclick="image_upload('color<?php echo $color_row; ?>_<?php echo $color_image_row; ?>', 'color_preview<?php echo $color_row; ?>_<?php echo $color_image_row; ?>');" />	
										                    </td>
							                                <td class="left">
							              	                    <a class="button" style="text-decoration: none;" onclick="$('#color_image_row<?php echo $color_row; ?>_<?php echo $color_image_row; ?>').remove();"><span><?php echo 'Remove image'; ?></span></a>
										                    </td>
							                            </tr>
							                        </tbody>
							                        <?php $color_image_row++; ?>
						                        <?php } ?>
						                        <tfoot>
						                            <tr>
						                                <td></td>
						                                <td class="left"><a onclick="addListColorImage(<?php echo $color_row; ?>);" class="button"><span><?php echo 'Add image'; //$button_add_image; ?></span></a></td>
						                            </tr>
						                        </tfoot>
						                    </table>								
			                            </td>
			                        </tr>							  
						        </tbody> 						    
		                    </table>
					        <input type="hidden" name="product_color[<?php echo $color_row; ?>][image]" value="" />
		                </div>					 
					<?php $color_row++; ?>
                <?php } ?>	
	        </div>
			<?php foreach ($languages as $language) { ?>
				<input type="hidden" name="product_color_language[]" value="<?php echo $language['language_id']; ?>" />					
			<?php } ?>
	    </div>
        <?php } ?>
	</div>		
    </form>
    </div>
</div>
<script type="text/javascript" src="view/javascript/ckeditor/ckeditor.js"></script>
<script type="text/javascript"><!--
<?php foreach ($languages as $language) { ?>
CKEDITOR.replace('description<?php echo $language['language_id']; ?>', {
	filebrowserBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashBrowseUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserImageUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>',
	filebrowserFlashUploadUrl: 'index.php?route=common/filemanager&token=<?php echo $token; ?>'
});
<?php } ?>
//--></script>

<!--[if IE]>
<script type="text/javascript" src="view/javascript/json2.js"></script>   
<![endif]-->
<script type="text/javascript"><!--
function addRelated() {
	$('#product :selected').each(function() {
		$(this).remove();
		
		$('#related option[value=\'' + $(this).attr('value') + '\']').remove();
		
		$('#related').append('<option value="' + $(this).attr('value') + '">' + $(this).text() + '</option>');
		
		$('#product_related input[value=\'' + $(this).attr('value') + '\']').remove();
		
		$('#product_related').append('<input type="hidden" name="product_related[]" value="' + $(this).attr('value') + '" />');
	});
}

function removeRelated() {
	$('#related :selected').each(function() {
		$(this).remove();
		
		$('#product_related input[value=\'' + $(this).attr('value') + '\']').remove();
	});
}

function getProducts() {
	$('#product option').remove();
	
	$.ajax({
		url: 'index.php?route=catalog/product/category&token=<?php echo $token; ?>&category_id=' + $('#category').attr('value'),
		dataType: 'json',
		success: function(data) {
			for (i = 0; i < data.length; i++) {
	 			//$('#product').append('<option value="' + data[i]['product_id'] + '">' + data[i]['name'] + ' (' + data[i]['model'] + ') </option>');
                $('#product').append('<option value="' + data[i]['product_id'] + '">' + data[i]['name'] + ' (' + data[i]['sku'] + ') </option>');
			}
		}
	});
}

function getRelated() {
	$('#related option').remove();
	
	$.ajax({
		url: 'index.php?route=catalog/product/related&token=<?php echo $token; ?>',
		type: 'POST',
		dataType: 'json',
		data: $('#product_related input'),
		success: function(data) {
			$('#product_related input').remove();
			
			for (i = 0; i < data.length; i++) {
	 			$('#related').append('<option value="' + data[i]['product_id'] + '">' + data[i]['name'] + ' (' + data[i]['product_id'] + ') </option>');
				
				$('#product_related').append('<input type="hidden" name="product_related[]" value="' + data[i]['product_id'] + '" />');
			} 
		}
	});
}

getProducts();
getRelated();
//--></script>

<script type="text/javascript"><!--
<?php if(isset($show_attribute_option)){ ?> 
$('#option').bind('change', function() {
	$('.option').hide(); 
    $('.option_value').hide();  	
                          
    if($('#' + $('#option option:selected').attr('rel')) != ''){                            
        $('#' + $('#option option:selected').attr('rel')).show();
    }
	$('#' + $('#option option:selected').attr('value')).show();
});

$('#option option:first').attr('selected', 'selected'); 
$('#option').trigger('change');
<?php } ?>

//$('#option .attribute_item').bind('click', function() {
$('#option .attribute_item').live('click', function() {
    $('.option').hide(); 
    $('.option_value').hide();  
    $('#option .attribute_item').removeClass('attribute_selected');    
        
    $(this).addClass('attribute_selected');                   
    if($('#' + $('#option .attribute_selected').attr('alt')) != ''){                            
        $('#' + $('#option .attribute_selected').attr('alt')).show();
    }
    $('#' + $('#option .attribute_selected').attr('rel')).show();
});

$('#option div.attribute_item[alt^=\'option\']:first').trigger('click');
//--></script>

<script type="text/javascript"><!--							 
var option_row = <?php echo $option_row + 0; ?>;  
var option_value_row = <?php echo $option_value_row; ?>;  
function addAttribute(){
    var selected_item = $('#attribute_group option:selected');  
    var name = $(selected_item).attr('alt');
    var description = $(selected_item).text();
    var sort = $(selected_item).attr('rel');
    var attribute_group = $(selected_item).val();      
  
    if($('div[id=\'option' + attribute_group + '\']').children().size() > 0){
        if(!confirm('Attribute "' + description + '" will be replace. Are you sure?')){
            return false;
        }
    }  
    
    option_row = attribute_group;  
    option_value_row = 0;              
    html  = '<div id="option' + option_row + '" class="option">';
    html +=     '<table class="form">';
    html +=         '<tr>';
    html +=             '<td width="30%">';
                            <?php foreach ($languages as $language) { ?>
    html +=                     '<input type="hidden" name="product_option[' + option_row + '][language][<?php echo $language['language_id']; ?>][name]" value="' + name + '" />';
                            <?php } ?> 
    html +=                 '<input type="hidden" name="product_option[' + option_row + '][description]" value="' + description + '" />';
    html +=                 '<input type="hidden" name="product_option[' + option_row + '][sort_order]" value="' + sort + '" />';
    html +=                 '<input type="hidden" name="product_option[' + option_row + '][attribute_id]" value="' + attribute_group + '" />';
    html +=                 '<b>Attribute name:</b>&nbsp;&nbsp;&nbsp;&nbsp;' + name + '&nbsp;&nbsp;(' + description + ')';
    html +=             '</td>';                                                                                           
    html +=             '<td width="50%"><b><?php echo $entry_sort_order; ?></b>&nbsp;&nbsp;&nbsp;&nbsp;' + sort + '</td>';
    html +=             '<td width="20%" align="right"><a onclick="removeOption(' + option_row + ');" class="button"><span><?php echo $button_remove_attribute; ?></span></a></td>';
    html +=         '</tr>';    
    html +=     '</table>'; 
    html +=     '<div id="option_values' + option_row + '"></div>';    
    html += '</div>';
   
    $.ajax({
        url: 'index.php?route=catalog/product/attributeValues&token=<?php echo $token; ?>',
        type: 'POST',
        data: 'attribute_id=' + encodeURIComponent(attribute_group),
        dataType: 'text',
        success: function(data) {  
            <?php if(isset($show_attribute_option)){ ?> 
            $('div[id=\'option' + option_row + '\']').remove();
            $('#option option[value=\'option' + option_row + '\']').remove();              
            $('#option option[value^=\'option' + option_row + '_\']').remove();     
             
            $('#options').append(html);    
            $('#option').append('<option value="option' + option_row + '">' + description + '</option>');
            <?php } ?>              
            
            $('div[id=\'option' + option_row + '\']').remove();
            $('#option div.attribute_item[rel^=\'option' + option_row + '\']').remove();              
             
            $('#options').append(html);              
            $('#option').append('<div class="attribute_item attribute_header" rel="option' + option_row + '">' + description + '</div>');
            
            var values = JSON.parse(data);     
            $(values).each(function(index, item){
                addAttributeValues(option_row, item['value_id'], item['name'], item['sort_order']);    
            });  
            
            $('#option div.attribute_item[rel^=\'option' + option_row + '_\']:last').trigger('click');          
        }
    });
    
    //option_row++;    
}

function updateAttribute(){
    var selected_item = $('#attribute_group option:selected');  
    var name = $(selected_item).text();    
    var sort = $(selected_item).attr('rel');
    var attribute_group = $(selected_item).val();      
    
    option_row = attribute_group; 
    exist_items = $('input.attribute_value_id' + option_row);                 
    $.ajax({
        url: 'index.php?route=catalog/product/attributeValues&token=<?php echo $token; ?>',
        type: 'POST',
        data: 'attribute_id=' + encodeURIComponent(attribute_group),
        dataType: 'text',
        success: function(data) {  
            var check = false;    
            var values = JSON.parse(data);     
            $(values).each(function(index, item){
                for(i = 0; i < exist_items.length; i++){
                    check = exist_items[i].value == item['value_id'];
                    if(check){
                        break;
                    }
                };
                if(!check){
                    addAttributeValues(option_row, item['value_id'], item['name'], item['sort_order']);    
                }                  
            });            
        }
    });
    
    $('#option option[value=\'option' + option_row + '_' + option_value_row + '\']').attr('selected', 'selected');    
    $('#option').trigger('change');
}

function addAttributeValues(option_id, value_id, name, sort){       
    html  = '<div id="option' + option_id + '_' + option_value_row + '" class="option_value">'; 
    html  +=    '<table class="form">';
    html  +=         '<tr>';
    html  +=            '<td>';
                            <?php foreach ($languages as $language) { ?>                                                    
    html  +=                    '<input type="hidden" name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][language][<?php echo $language['language_id']; ?>][name]" value="' + name + '" />';                                                    
                            <?php } ?>
    html  +=                '<input type="hidden" name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][sort_order]" value="' + sort + '" />';
    html  +=                '<input type="hidden" name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][attribute_id]" value="' + option_id + '" />';
    html  +=                '<input type="hidden" name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][attribute_value_id]" value="' + value_id + '" class="attribute_value_id' + option_id + '" />';
    html  +=                'Attribute value:\u00A0\u00A0' + name;
    html  +=            '</td>';
    html  +=            '<td><?php echo $entry_sort_order; ?>\u00A0\u00A0' + sort + '</td>';    
    html  +=        '</tr>';
    html  +=        '<tr>';
    html  +=            '<td><?php echo $entry_product_option_number; ?></td>';
    html  +=            '<td><input type="text" name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][product_option_number]" value="" /></td>';
    html  +=        '</tr>';
    html  +=        '<tr>';
    html  +=            '<td><?php echo $entry_quantity; ?></td>';
    html  +=            '<td><input type="text" name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][quantity]" value="1" size="2" /></td>';
    html  +=        '</tr>';
    html  +=        '<tr>';
    html  +=            '<td><?php echo $entry_subtract; ?></td>';
    html  +=            '<td>';
    html  +=                '<select name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][subtract]">';    
    html  +=                    '<option value="1" selected="selected"><?php echo $text_yes; ?></option>';
    html  +=                    '<option value="0"><?php echo $text_no; ?></option>';                                
    html  +=                '</select>';
    html  +=            '</td>';
    html  +=        '</tr>';
    html  +=        '<tr>';
    html  +=            '<td><?php echo $entry_price; ?></td>'
    html  +=            '<td><input type="text" name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][price]" value="0" /></td>';
    html  +=        '</tr>';
    html  +=        '<tr>';
    html  +=            '<td><?php echo $entry_prefix; ?></td>';
    html  +=            '<td>';
    html  +=                '<select name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][prefix]">';
    html  +=                    '<option value="+" selected="selected"><?php echo $text_plus; ?></option>';
    html  +=                    '<option value="-"><?php echo $text_minus; ?></option>';
    html  +=                '</select>';
    html  +=            '</td>';
    html  +=        '</tr>';
                    <?php if(isset($show_attribute_option)){ ?>
    html  +=        '<tr>';
    html  +=            '<td colspan="2"><a onclick="removeOptionValue(\'' + option_id + '_' + option_value_row + '\');" class="button"><span><?php echo $button_remove_attribute_value; ?></span></a></td>';
    html  +=        '</tr>';
                    <?php } ?>
    html  +=    '</table>';
    html += '</div>';

    $('#option_values' + option_id).append(html);   
    
    <?php if(isset($show_attribute_option)){ ?> 
    option = $('#option option[value^=\'option' + option_id + '_\']:last');     
    if (option.size()) {
        option.after('<option value="option' + option_id + '_' + option_value_row + '" rel="option'+ option_id + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + name + '</option>');
    } 
    else {
        $('#option option[value=\'option' + option_id + '\']').after('<option value="option' + option_id + '_' + option_value_row + '" rel="option'+ option_id + '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + name + '</option>');
    } 
    
    $('#option option[value=\'option' + option_id + '_' + option_value_row + '\']').attr('selected', 'selected');    
    $('#option').trigger('change');
    <?php } ?>
    
    var option = $('#option div.attribute_item[rel^=\'option' + option_id + '_\']:last'); 
    var attr_item = '';
    attr_item += '<div class="attribute_item" rel="option' + option_id + '_' + option_value_row + '" alt="option' + option_id + '">';
    attr_item +=    '\u00A0\u00A0\u00A0\u00A0<input type="checkbox" class="attribute_item_value" name="product_option[' + option_id + '][product_option_value][' + option_value_row + '][select_attribute]" rel="option' + option_id + '" alt="option' + option_id + '_' + option_value_row + '" />';
    attr_item +=    '\u00A0\u00A0' + name;
    attr_item += '</div>';
        
    if (option.size()) {         
        option.after(attr_item);
    } 
    else {
        $('#option div.attribute_header[rel=\'option' + option_id + '\']').after(attr_item);
    }     
    //$('#option div.attribute_item[rel=\'option' + option_id + '_' + option_value_row + '\']').trigger('click');
    
    option_value_row++;
}

function removeOption(option_row) {
    $('#option div.attribute_item[rel=\'option' + option_row + '\']').remove();
    $('#option div.attribute_item[alt=\'option' + option_row + '\']').remove();
    //$('#option div.attribute_item[rel^=\'option' + option_row + '_\']').remove();
    
    $('#options div[id=\'option' + option_row + '\']').remove();
}

function removeOptionValue(option_value_row) {
	$('#option option[value=\'option' + option_value_row + '\']').remove();  	
	$('#option' + option_value_row).remove();
}
//--></script>
<script type="text/javascript"><!--
var discount_row = <?php echo $discount_row; ?>;

function addDiscount() {
	html  = '<tbody id="discount_row' + discount_row + '">';
	html += '<tr>'; 
    //html += '<td class="left"><select name="product_discount[' + discount_row + '][customer_group_id]" style="margin-top: 3px;">';
    <?php foreach ($customer_groups as $customer_group) { ?>
    //html += '<option value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>';
    <?php } ?>
    //html += '</select></td>';		
    //html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][quantity]" value="1" size="2" /></td>';
    //html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][priority]" value="" size="2" /></td>';
	html += '<td class="left">';
    html +=     '<input type="text" name="product_discount[' + discount_row + '][price]" value="" />';
    html +=     '<input type="hidden" name="product_discount[' + discount_row + '][customer_group_id]" value="<?php echo $default_discount_group; ?>" />';
    html +=     '<input type="hidden" name="product_discount[' + discount_row + '][priority]" value="1" />';
    html +=     '<input type="hidden" name="product_discount[' + discount_row + '][quantity]" value="1" />';
    html += '</td>';
    html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][date_start]" value="" class="date" /></td>';
	html += '<td class="left"><input type="text" name="product_discount[' + discount_row + '][date_end]" value="" class="date" /></td>';
	html += '<td class="left"><a onclick="removeDiscount(' + discount_row + ');" class="button"><span><?php echo $button_remove; ?></span></a></td>';
	html += '</tr>';	
    html += '</tbody>';
	
	$('#discount tfoot').before(html);		
	$('#discount_row' + discount_row + ' .date').datepicker({dateFormat: 'yy-mm-dd'});	
    $('#discount tfoot').hide();
    
	discount_row++;    
}

function removeDiscount(row){
    $('#discount_row' + row).remove();
    $('#discount tfoot').show();
}
//--></script>
<script type="text/javascript"><!--
var special_row = <?php echo $special_row; ?>;

function addSpecial() {
	html  = '<tbody id="special_row' + special_row + '">';
	html += '<tr>'; 
    //html += '<td class="left"><select name="product_special[' + special_row + '][customer_group_id]">';
    <?php foreach ($customer_groups as $customer_group) { ?>
    //html += '<option value="<?php echo $customer_group['customer_group_id']; ?>"><?php echo $customer_group['name']; ?></option>';
    <?php } ?>
    //html += '</select></td>';		
//    /html += '<td class="left"><input type="text" name="product_special[' + special_row + '][priority]" value="" size="2" /></td>';
    html += '<td class="left">';
    html +=     '<input type="hidden" name="product_special[' + special_row + '][customer_group_id]" value="<?php echo $default_discount_group; ?>" />';
    html +=     '<input type="hidden" name="product_special[' + special_row + '][priority]" value="1" />';
    html +=     '<input type="text" name="product_special[' + special_row + '][quantity]" value="" size="5" />';
    html += '</td>';    
	html += '<td class="left"><input type="text" name="product_special[' + special_row + '][price]" value="" /></td>';
    html += '<td class="left"><input type="text" name="product_special[' + special_row + '][date_start]" value="" class="date" /></td>';
	html += '<td class="left"><input type="text" name="product_special[' + special_row + '][date_end]" value="" class="date" /></td>';
	html += '<td class="left"><a onclick="$(\'#special_row' + special_row + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
	html += '</tr>';
    html += '</tbody>';
	
	$('#special tfoot').before(html);
 
	$('#special_row' + special_row + ' .date').datepicker({dateFormat: 'yy-mm-dd'});
	
	special_row++;
}
//--></script>
<script type="text/javascript" src="view/javascript/jquery/ui/ui.draggable.js"></script>
<script type="text/javascript" src="view/javascript/jquery/ui/ui.resizable.js"></script>
<script type="text/javascript" src="view/javascript/jquery/ui/ui.dialog.js"></script>
<script type="text/javascript" src="view/javascript/jquery/ui/external/bgiframe/jquery.bgiframe.js"></script>
<script type="text/javascript"><!--
function image_upload(field, preview) {
	$('#dialog').remove();
	
	$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager&token=<?php echo $token; ?>&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	
	$('#dialog').dialog({
		title: '<?php echo $text_image_manager; ?>',
		close: function (event, ui) {
			if ($('#' + field).attr('value')) {
				$.ajax({
					url: 'index.php?route=common/filemanager/image&token=<?php echo $token; ?>',
					type: 'POST',
					data: 'image=' + encodeURIComponent($('#' + field).attr('value')),
					dataType: 'text',
					success: function(data) {
						$('#' + preview).replaceWith('<img src="' + data + '" alt="" id="' + preview + '" class="image" onclick="image_upload(\'' + field + '\', \'' + preview + '\');" />');
                        
                        if(data.indexOf('no_image') > 0){                             
                            $('#' + field).attr('value', '');
                        }
					}                     
				});
			}
		},	
		bgiframe: false,
		width: 700,
		height: 400,
		resizable: false,
		modal: false
	});
};

$('#video_preview').bind('click', video_upload);

function video_upload(even) {
    even.preventDefault();
    
    var field = 'video'; 
    var preview = 'video_preview';
    
    $('#dialog').remove();
    
    $('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager/index_video&token=<?php echo $token; ?>&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
    
    $('#dialog').dialog({
        title: '<?php echo $text_video_manager; ?>',
        close: function (event, ui) {
            if ($('#' + field).attr('value')) {
                $.ajax({
                    url: 'index.php?route=common/filemanager/video&token=<?php echo $token; ?>',
                    type: 'POST',
                    data: 'video=' + encodeURIComponent($('#' + field).attr('value')),
                    dataType: 'text',
                    success: function(data) {
                        $('#' + preview).attr('src', data);
                    }
                });
            }
        },    
        bgiframe: false,
        width: 700,
        height: 400,
        resizable: false,
        modal: false
    });
};

//--></script>
<script type="text/javascript"><!--
var image_row = <?php echo $image_row; ?>;

function addImage() {
    html  = '<tbody id="image_row' + image_row + '">';
	html += '<tr>';
	html += '<td class="left"><input type="hidden" name="product_image[' + image_row + ']" value="" id="image' + image_row + '" /><img src="<?php echo $no_image; ?>" alt="" id="preview' + image_row + '" class="image" onclick="image_upload(\'image' + image_row + '\', \'preview' + image_row + '\');" /></td>';
	html += '<td class="left"><a onclick="$(\'#image_row' + image_row  + '\').remove();" class="button"><span><?php echo $button_remove; ?></span></a></td>';
	html += '</tr>';
	html += '</tbody>';
	
	$('#images tfoot').before(html);
	
	image_row++;
}

$('#color_list').bind('change', function() {
	$('#color_item .option_color').hide();
	$('#' + $('#color_list option:selected').attr('value')).show();
});
$('#color_list').bind('click', function(event) {
	if ($(this).val() != 'option_color_00') {
		event.preventDefault();
	}
});

$('#color_list option:first').attr('selected', 'selected');
$('#color_list').trigger('change');

var color_row = <?php echo $colors_row; ?>;
function addColorImage(name, sort_order, image, preview) {
    var html = '';
        
	html += '<tr id="color_row' + color_row + '">';
	html +=     '<td class="left">';
    html +=         '<input type="hidden" name="product_color[' + color_row + '][image]" value="" id="color' + color_row + '" />';
    html +=         '<img src="<?php echo $no_image; ?>" alt="" id="color_preview' + color_row + '" class="image" onclick="image_upload(\'color' + color_row + '\', \'color_preview' + color_row + '\');" /></td>';
    html +=     '<td class="left">';
    html +=         '<span style="float:left; margin-left:10px;">' + name + '</span><br />';    
    html +=         '<input type="hidden" name="product_color[' + color_row + '][name]" value="' + name + '" id="color_name' + color_row + '" />';
    html +=         '<input type="hidden" name="product_color[' + color_row + '][sort_order]" value="' + sort_order + '" />';
    html +=         '<input type="hidden" name="product_color[' + color_row + '][color_image]" value="' + image + '" id="color_image' + color_row + '" />';    
	html +=         '<img src="' + preview + '" alt="" id="color_image_preview' + color_row + '" class="image" style="float:left; margin-left:10px;" />';
	html +=     '</td>';
	html +=     '<td class="left"><a onclick="removeColorImage(\'color_row' + color_row  + '\');" class="button" style="text-decoration:none;"><span><?php echo $button_remove; ?></span></a></td>';
	html += '</tr>';	
	
    if($('#colors #color_body').length > 0){
	    $('#colors #color_body').append(html);
    }
    else{
        $('#colors tfoot').before('<tbody id="color_body">' + html + '</tbody>');    
    }
	
	color_row++;
}

function removeColorImage(colors_row){        
    $('#' + colors_row).remove();    
    if($('#colors #color_body').children().size() <= 0){ 
        $('#colors #color_body').remove();
    }
}

function addColorValues(){ 
    //if($('#colors #color_body').length > 0){
    if($('#color_item div[id*=\'option_color\']').children().size() > 0){
        if(!confirm('All values will be replace. Are you sure?')){
            return false;
        }
    }
    
    //color_row = 0;   
    color_option_row = 0;  
      
    $.ajax({
        url: 'index.php?route=catalog/product/colorValues&token=<?php echo $token; ?>',
        type: 'POST',
        data: 'color_group_id=' + encodeURIComponent($('#color_group').val()),
        dataType: 'text',
        success: function(data) { 
            //$('#colors #color_body').remove();
            $('#color_list option[value*=\'option_color\']').each(function(){
                $(this).remove();    
            });    
            $('#color_item div[id*=\'option_color\']').each(function(){
                $(this).remove();    
            });
    
            var values = JSON.parse(data);
            $(values).each(function(index, item){
                //addColorImage(item['name'], item['sort_order'], item['image'], item['preview']);    
                addColorOption(item['value_id'], item['name'], item['sort_order'], item['image'], item['preview']);    
            });
            
            $('#color_list option[value=\'option_color0\']').attr('selected', 'selected');               
            $('#color_list').trigger('change');
        }
    });        
}
   
function updateColorValues(){     
    if($('#color_group').val() != <?php echo $color_attribute_id; ?>){
        if(!confirm('You\'ve selected another color group, all current values will be deleted. Are you sure?')){
            return false;
        }
    }
    
    exist_items = $('#color_item input[id*=\'color_av_id\']');       
    $.ajax({
        url: 'index.php?route=catalog/product/colorValues&token=<?php echo $token; ?>',
        type: 'POST',
        data: 'color_group_id=' + encodeURIComponent($('#color_group').val()),
        dataType: 'text',
        success: function(data) {             
            var values = JSON.parse(data);
            var check = false;
            $(values).each(function(index, item){                             
                for(i = 0; i < exist_items.length; i++){
                    check = exist_items[i].value == item['value_id'];
                    if(check){
                        break;
                    }
                };
                if(!check){
                    addColorOption(item['value_id'], item['name'], item['sort_order'], item['image'], item['preview']);    
                }
            }); 
             
            $('#color_list option[value=\'option_color' + (color_option_row - 1) + '\']').attr('selected', 'selected');               
            $('#color_list').trigger('change');
        }
    });
}
    
var color_option_row = <?php echo $color_row; ?>;
function addColorOption(value_id, name, sort_order, image, preview) {
	html  = '<div id="option_color' + color_option_row + '" class="option_color">';
	html +=     '<table class="form">';
	html +=         '<tbody>';
	html +=             '<tr>';
    html +=                 '<td style="width:250px;">';
    html +=                     '<input type="hidden" name="product_color[' + color_option_row + '][color_av_id]" value="'+ value_id + '" id="color_av_id' + color_option_row + '" />';
    html +=                     '<input type="hidden" name="product_color[' + color_option_row + '][name]" value="' + name + '" id="color_name' + color_option_row + '" />';
    html +=                     '<input type="hidden" name="product_color[' + color_option_row + '][sort_order]" value="' + sort_order + '" id="color_sort_order' + color_option_row + '" />';
    html +=                     '<input type="hidden" name="product_color[' + color_option_row + '][color_image]" value="' + image + '" id="color_image' + color_option_row + '" />';
    html +=                     '<span style="float:left; margin-left:10px; width:50px;">' + name + '</span>';
    html +=                     '<img src="' + preview + '" alt="" id="color_image_preview' + color_option_row + '" class="image" style="float:left; margin-left:10px;" />';
    html +=                 '</td>';
    html +=                 '<td><?php echo $entry_sort_order; ?>\u00A0' + sort_order + '</td>';
    html +=                 '<td><a class="button" onclick="removeColorOption(' + color_option_row + ');" style="float:right; margin-right:2px;"><span>Remove color</span></a></td>';
	html +=             '</tr>';
	html +=             '<tr>';
	html +=                 '<td colspan="3">';
	html +=                     '<table class="list" id="color_images' + color_option_row + '">';
	html +=                         '<thead>';
	html +=                             '<tr>';
	html +=                                 '<td style="width: 70%;" class="left">Image: </td>';
	html +=                                 '<td></td>';
	html +=                             '</tr>';
	html +=                         '</thead>'
	html +=                         '<tfoot>';
	html +=                             '<tr>';
	html +=                                 '<td></td>';
	html +=                                 '<td class="left"><a class="button" onclick="addListColorImage(' + color_option_row + ');"><span>Add image</span></a></td>';
	html +=                             '</tr>';
	html +=                         '</tfoot>';
	html +=                     '</table>';								
	html +=                 '</td>';
	html +=             '</tr>';
	html +=         '</tbody>'; 
	html +=         '<tfoot>';          	
	html +=             '<tr>';			              
	html +=                 '<td style="border-bottom: medium none;" colspan="2">';
	html +=                     
	html +=                 '</td>';			              
	html +=             '</tr>';
	html +=         '</tfoot>';
	html +=     '</table>';
	html +=     '<input type="hidden" value="" name="product_color[' + color_option_row + '][image]" />';
	html += '</div>';
		 
	$('#color_item').append(html);
	
	$('#color_list').append('<option value="option_color' + color_option_row + '">\u00A0' + name + '</option>');
	//$('#color_list option[value=\'option_color' + color_option_row + '\']').attr('selected', 'selected');
	//$('#color_list').trigger('change');

	color_option_row++;
}

function removeColorOption(row) {
	$('#color_list option[value=\'option_color' + row + '\']').remove();	
	$('#color_item div[id=\'option_color' + row + '\']').remove();
	$('#color_list').trigger('change');
}

var color_image_row = <?php echo $color_image_row; ?>;
function addListColorImage(color_row) {
    html  = '<tbody id="color_image_row' + color_row + '_' + color_image_row + '">';
	html +=     '<tr>';
	html +=         '<td class="left">';
	html +=             '<input type="hidden" name="product_color[' + color_row + '][image_list][' + color_image_row + ']" value="" id="color' + color_row + '_' + color_image_row + '" />';
	html +=             '<img src="<?php echo $no_image; ?>" alt="" id="color_preview' + color_row + '_' + color_image_row + '" class="image" onclick="image_upload(\'color' + + color_row + '_' + color_image_row + '\', \'color_preview' + + color_row + '_' + color_image_row + '\');" />';
	html +=         '</td>';    
	html +=         '<td class="left">';
	html +=             '<a style="text-decoration: none;" onclick="$(\'#color_image_row' + color_row + '_' + color_image_row  + '\').remove();" class="button"><span><?php echo "Remove image"; //$button_remove; ?></span></a></td>';
	html +=     '</tr>';
	html += '</tbody>';
	
	$('#color_images' + color_row + ' tfoot').before(html);
	
	color_image_row++;
}

function changeColorName(color_row, value){
	$('#color_list option[value=\'option_color' + color_row + '\']').text('\u00A0' + value);
}

function image_upload_color(field, preview) {
	$('#dialog').remove();
	
	$('#content').prepend('<div id="dialog" style="padding: 3px 0px 0px 0px;"><iframe src="index.php?route=common/filemanager&token=<?php echo $token; ?>&field=' + encodeURIComponent(field) + '" style="padding:0; margin: 0; display: block; width: 100%; height: 100%;" frameborder="no" scrolling="auto"></iframe></div>');
	
	$('#dialog').dialog({
		title: '<?php echo $text_image_manager; ?>',
		close: function (event, ui) {
			if ($('#' + field).attr('value')) {
				$.ajax({
					url: 'index.php?route=common/filemanager/image_color&token=<?php echo $token; ?>',
					type: 'POST',
					data: 'image=' + encodeURIComponent($('#' + field).attr('value')),
					dataType: 'text',
					success: function(data) {
						$('#' + preview).replaceWith('<img src="' + data + '" alt="" id="' + preview + '" class="image" onclick="image_upload_color(\'' + field + '\', \'' + preview + '\');" style="float:left; margin-left:10px;" />');
					}
				});
			}
		},	
		bgiframe: false,
		width: 700,
		height: 400,
		resizable: false,
		modal: false
	});
};

//--></script>
<script type="text/javascript" src="view/javascript/jquery/ui/ui.datepicker.js"></script>
<script type="text/javascript"><!--
$(document).ready(function() {
	$('.date').datepicker({dateFormat: 'yy-mm-dd'});
});
//--></script>
<script type="text/javascript"><!--
$.tabs('#tabs a'); 
$.tabs('#languages a'); 
//--></script>
<?php echo $footer; ?>
